<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="java.util.*"%>
<%@ page import="com.esaheki.flashcards.dao.*"%>
<%@ page import="com.esaheki.flashcards.classes.*"%>

<div id="leftnav">
<jsp:useBean id="uDao" class="com.esaheki.flashcards.dao.UserDAO" scope="session"/>
<jsp:useBean id="catDao" class="com.esaheki.flashcards.dao.CategoryDAO" scope="session"/>
<%
String type = "";
if (request.getParameter("type") != null) {
	type = request.getParameter("type");
}
int idn = 0;
if (request.getParameter("id") != null) {
	idn = Integer.parseInt(request.getParameter("id"));
}
String style = "inactive";

ArrayList<User> userlist = uDao.getUserList();
for (User user : userlist) {
	style = "inactive";
	if (type.equals("user")) {
		if (user.getId() == idn) {
			style = "active";
		}
	}
%>
<h2><a class="<%=style %>" href="table.jsp?type=user&id=<%=user.getId() %>"><%=user.getName()%></a></h2>
<ul>
<%
	
	ArrayList<Category> catlist = catDao.getCategoryList(user);
	for (Category cat : catlist) {
		style = "inactive";
		if (type.equals("cat")) {
			if (cat.getId() == idn) {
				style = "active";
			}
		}
%><li><a class="<%=style %>" href="table.jsp?type=cat&id=<%=cat.getId() %>"><%=cat.getName()%></a></li>
<%
}
%></ul>
<%
}
%>
<br>
<a class="greenlink" href="add.jsp?type=user">Add User</a>
</div>